package com.nintendo.controller;

import com.nintendo.config.MinioConfig;


import com.nintendo.response.Result;
import com.nintendo.util.MinioUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/minio")
@Slf4j
public class MinioController {
    @Autowired
    private MinioUtils minioUtils;
    @Autowired
    private MinioConfig minioConfig;
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
        log.info(file.getOriginalFilename());
        String url = minioUtils.upload(file);
        url = "http://"+minioConfig.getEndpoint()+":"+minioConfig.getPort()+"/"+url;
        log.info(url);
        return Result.ok(url);
    }
}
